<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/StoresSystem' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/StoresSystem/ShopsList' }">门店列表</el-breadcrumb-item>
      <el-breadcrumb-item>商品列表</el-breadcrumb-item>
    </el-breadcrumb>

    <el-tabs type="border-card">
      <el-tab-pane label="库存商品">
        <span slot="label">
          <i class="el-icon-date"></i> 库存商品
        </span>

        <div class="bians">
          <el-input placeholder="请输入查询内容" v-model="search1.searchValue" class="input-with-select">
            <el-select v-model="search1.searchType" slot="prepend" placeholder="请选择">
              <el-option label="商品名字" value="name"></el-option>
              <el-option label="商品价格" value="price"></el-option>
              <el-option label="商品数量" value="num"></el-option>
            </el-select>
            <el-button slot="append" icon="el-icon-search" @click="getGoodsunsoldAsync(search1)"></el-button>
          </el-input>
        </div>
        <el-table size="small" :data="unsoldGoods" style="width: 100%" height="300px">
          <el-table-column label="商品编号" prop="_id" width="190%"></el-table-column>
          <el-table-column label="商品名字" prop="name"></el-table-column>
          <el-table-column label="商品价格" prop="price"></el-table-column>
          <el-table-column label="商品数量" prop="num"></el-table-column>
          <el-table-column label="商品状态" prop="state"></el-table-column>
          <el-table-column label="商品门店" prop="shopsId.name"></el-table-column>
          <el-table-column label="商品图片">
            <template slot-scope="scope">
              <img class="studentsImage" :src="scope.row.imagePath" />
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button size="small" @click="updateGoods(scope.row)">修改</el-button>

              <el-dialog title="修改信息" :visible.sync="centerDialogVisible">
                <el-form :model="getUpdateGood">
                  <el-form-item label="商品名字：">
                    <el-input autocomplete="off" v-model="getUpdateGood.name"></el-input>
                  </el-form-item>
                  <el-form-item label="商品价格：">
                    <el-input autocomplete="off" v-model="getUpdateGood.price"></el-input>
                  </el-form-item>
                  <el-form-item label="商品数量：">
                    <el-input autocomplete="off" v-model="getUpdateGood.num"></el-input>
                  </el-form-item>
                </el-form>
                <div slot="footer" class="dialog-footer">
                  <el-button @click="centerDialogVisible = false">取 消</el-button>
                  <el-button type="primary" @click="updata(getUpdateGood)" :plain="true">确 定</el-button>
                </div>
              </el-dialog>

              <el-button size="mini" type="danger" @click="removeGoods(scope.row)" :plain="true">上架</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <el-pagination
            background
            @size-change="handleSizeChange1"
            @current-change="handleCurrentChange1"
            :current-page="pageData1.currentPage"
            :page-sizes="[3,4,5,6,7]"
            :page-size="pageData1.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageData1.total"
          ></el-pagination>
        </div>
      </el-tab-pane>
      <el-tab-pane label="下架商品">
        <span slot="label">
          <i class="el-icon-date"></i> 下架商品
        </span>

        <div class="bians">
          <el-input placeholder="请输入查询内容" v-model="search2.searchValue" class="input-with-select">
            <el-select v-model="search2.searchType" slot="prepend" placeholder="请选择">
              <el-option label="商品名字" value="name"></el-option>
              <el-option label="商品价格" value="price"></el-option>
              <el-option label="商品数量" value="num"></el-option>
            </el-select>
            <el-button slot="append" icon="el-icon-search" @click="getGoodsunsoldAsync1(search2)"></el-button>
          </el-input>
        </div>
        <el-table size="small" :data="unsoldGoods1" style="width: 100%" height="300px">
          <el-table-column label="商品编号" prop="_id" width="190%"></el-table-column>
          <el-table-column label="商品名字" prop="name"></el-table-column>
          <el-table-column label="商品价格" prop="price"></el-table-column>
          <el-table-column label="商品数量" prop="num"></el-table-column>
          <el-table-column label="商品状态" prop="state"></el-table-column>
          <el-table-column label="商品门店" prop="shopsId.name"></el-table-column>
          <el-table-column label="商品图片">
            <template slot-scope="scope">
              <img class="studentsImage" :src="scope.row.imagePath" />
            </template>
          </el-table-column>
          <el-table-column label="操作">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="danger"
                @click="removeGoods(scope.row)"
                :plain="true"
              >重新上架</el-button>
            </template>
          </el-table-column>
        </el-table>
        <div class="block">
          <el-pagination
            background
            @size-change="handleSizeChange2"
            @current-change="handleCurrentChange2"
            :current-page="pageData2.currentPage"
            :page-sizes="[3,4,5,6,7]"
            :page-size="pageData2.pageSize"
            layout="total, sizes, prev, pager, next, jumper"
            :total="pageData2.total"
          ></el-pagination>
        </div>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>

<script>
import axios from "axios";
import { createNamespacedHelpers } from "vuex";
const {
  mapState,
  mapGetters,
  mapMutations,
  mapActions
} = createNamespacedHelpers("finishedGoods");

export default {
  data() {
    return {
      // search: {
      //   searchType: "",
      //   searchValue: ""
      // },
      centerDialogVisible: false,
      getUpdateGood: {
        name: "",
        price: "",
        num: "",
        shopsId: ""
      },
      search2: {
        searchType: "",
        searchValue: ""
      },
      search1: {
        searchType: "",
        searchValue: ""
      }
    };
  },
  computed: {
    ...mapState(["pageData2", "pageData1", "unsoldGoods", "unsoldGoods1"])
  },
  created() {
    this.getGoodsunsoldAsync(this.search1);
    this.getGoodsunsoldAsync1(this.search2);
  },
  methods: {
    ...mapMutations([]),
    ...mapActions([
      "handleCurrentChange1",
      "handleSizeChange1",
      "handleCurrentChange2",
      "handleSizeChange2",
      "getGoodsunsoldAsync",
      "getGoodsunsoldAsync1",
      // "deleteGoodsCellAsync",
      "updataGoodsCellAsync",
      "putonGoodsCellAsync"
    ]),
    //点击修改按钮
    updateGoods(row) {
      this.centerDialogVisible = true;
      this.getUpdateGood = { ...row };
      console.log(row);
    },

    //上架
    removeGoods(row) {
      this.putonGoodsCellAsync(row._id);
      this.$message({
        showClose: true,
        message: "上架成功",
        type: "success"
      });

      this.getGoodsunsoldAsync();
    },
    // //分页
    // handleCurrentChange(val) {
    //   this.changePage(val);
    //   this.getGoodsunsoldAsync();
    // },
    // handleSizeChange(val) {
    //   // console.log(`每页 ${val} 条`);
    //   this.changepageSize(val);
    //   this.getGoodsunsoldAsync();
    // },
    // 点击修改改变数据
    updata(newGoodData) {
      this.updataGoodsCellAsync({ ...newGoodData });
      //  this.getGoodsCellAsync();
      this.$message({
        showClose: true,
        message: "修改成功",
        type: "success"
      });
      this.centerDialogVisible = false;
    },
    //搜索商品
    // serchGoods1() {
    //   console.log();
    //   this.getGoodsunsoldAsync1(this.search1);
    // },
    // serchGoods2() {
    //   console.log();
    //   this.getGoodsunsoldAsync(this.search2);
    // },
  }
};
</script>

<style>
.el-breadcrumb {
  padding-left: 10px;
  height: 30px;
}
.el-tabs__content {
  padding-top: 0px !important;
}

.bians {
  height: 60px;
}
.input-with-select {
  height: 40%;
}

.el-tabs__nav-scroll {
  line-height: 35px;
}
.el-tabs__nav-scroll div {
  height: 100%;
}

.el-table__header-wrapper .has-gutter tr th {
  line-height: 40px;
}
.has-gutter .cell {
  text-align: center;
  font-size: 14px;
}
.el-table__row .cell {
  text-align: center;
}
.is-right button {
  margin-right: 5px;
}
.el-dialog {
  width: 500px;
}
.el-form-item {
  padding: 0 40px;
}
.el-dialog__header {
  display: flex;
}
.el-dialog .el-input {
  width: 260px;
}
.el-dialog__close {
  display: none;
}
.dialog-footer {
  padding-right: 40px;
}

.el-pagination {
  margin-top: 10px;
  height: 30px !important;
}
.studentsImage {
  width: 50px;
}
.el-select .el-input {
  width: 130px;
}
.input-with-select .el-input-group__prepend {
  background-color: #fff;
}
.bans {
  line-height: 60px;
}
.el-table_1_column_7 .cell img{
  width: 50px !important;
  height: 50px !important;
}
</style>